﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Entity.Car_Rental;
using Data.Car_Rental;
using Web.Commons.Helpers;

namespace Car_Rental.Controllers
{
    public class CarController : Controller
    {
        public CarController()
        {

        }
        //
        // GET: /Car/

        public ActionResult Index()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Index(FormCollection form)
        {

            Standard.RentalCar entity = new Standard.RentalCar();
            TryUpdateModel(entity);
            string Province = form["Province"];
            string City = form["City"];
            string District = form["District"];
            if (!string.IsNullOrEmpty(Province) && string.IsNullOrEmpty(City) && string.IsNullOrEmpty(District))
            {
                entity.ReturnCity = Province;
            }
            if (!string.IsNullOrEmpty(City) && string.IsNullOrEmpty(District))
            {
                entity.ReturnCity = City;
            }
            if (!string.IsNullOrEmpty(District))
            {
                entity.ReturnCity = District;
            }
            entity.ReturnShop = form["ReturnShopName"];
            try
            {
                Standard.ClientHelper.AddRentalCar(entity);
                if (entity.ProductID == 0 && string.IsNullOrEmpty(form["ProductID"]))
                    return RedirectToAction("Index", "Product");
                else
                    return RedirectToAction("Index", "Order", new { ProductID = form["ProductID"], Price = form["Price"], isquene = form["isquene"] });
            }
            catch (Exception)
            {
                return View();
            }
        }

    }
}
